package com.jokins.admin.vue.user.controller;


import com.jokins.admin.vue.user.param.SysUserChangePasswordParam;
import com.jokins.admin.vue.user.param.SysUserLoginParam;
import com.jokins.admin.vue.user.param.SysUserRegisterPasswordParam;
import com.jokins.admin.vue.user.service.SysUserService;
import com.jokins.admin.vue.user.vo.LoginStatsVo;
import com.jokins.admin.vue.user.vo.SysUserLoginVo;
import com.jokins.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈〉<br>
 *
 * @author Mr.Wang
 * @create 2025/1/1
 */
@RestController
@RequestMapping("/system")
public class SysLoginController {

    @Autowired
    private SysUserService sysUserService;

    @PostMapping("/login")
    public ResultData sysUserLogin(@RequestBody SysUserLoginParam param) {
        SysUserLoginVo sysUserLoginVo = sysUserService.sysUserLogin(param);
        Map<String, Object> map = new HashMap<>();
        map.put("sysUserLogin", sysUserLoginVo);
        return new ResultData("登录成功！", map);
    }

    @PostMapping("/changePassword")
    public ResultData sysUserChangePassword(@RequestBody SysUserChangePasswordParam param) {
        sysUserService.sysUserChangePassword(param);
        return new ResultData("密码修改成功！");
    }

    //TODO 注册
    @PostMapping("/register")
    public ResultData sysUserRegisterPassword(@RequestBody SysUserRegisterPasswordParam param) {
        Map<String, String> resultMap = sysUserService.sysUserRegisterPassword(param);
        return new ResultData("注册成功，请等待批准！",resultMap);
    }

    @GetMapping("/rePassword")
    public ResultData sysUserRePassword(String id) {
        String password = sysUserService.sysUserRePassword(id);
        return new ResultData("密码修改成功！",password);
    }

    @GetMapping("/loginStats")
    public ResultData getLoginStats() {
        List<LoginStatsVo> LoginStatsVoList = sysUserService.getLoginStats();
        return new ResultData("获取成功！",LoginStatsVoList);
    }
}
